<template>
  <div class="myacs">
    <MyHead :title="title"></MyHead>
    <div class="menus">
      <van-dropdown-menu>
        <van-dropdown-item @change="changeHotMenu" v-model="value1" :options="option1" />
        <van-dropdown-item @change="changeTimeMenu" v-model="value2" :options="option2" />
      </van-dropdown-menu>
    </div>
    <div>
      <CList :list="list"></CList>
    </div>
  </div>
</template>

<script>
import { todogetmslikes, todogetcollectlist, todogetpinglist } from '@/api/api'

export default {
  data() {
    return {
      type: "1",
      title: '',
      list: [],
      olist: [],
      value1: 0,
      value2: 0,
      option1: [
        { text: '热度排序', value: 0 },
        { text: '热度升序', value: 1 },
        { text: '热度降序', value: 2 },
      ],
      option2: [
        { text: '时间排序', value: 0 },
        { text: '时间升序', value: 1 },
        { text: '时间降序', value: 2 },
      ],
    }
  },
  methods: {
    sortDesc(a, b) {
      return b['hot'] - a['hot']
    },
    sortAsc(a, b, filed) {
      return a['hot'] - b['hot']
    },
    timesortDesc(a, b) {
      return new Date(b['date']).getTime() - new Date(a['date']).getTime()
    },
    timesortAsc(a, b, filed) {
      return new Date(a['date']).getTime() - new Date(b['date']).getTime()
    },
    changeHotMenu(value) {

      if (value == 0) {
        this.list = this.loda.cloneDeep(this.olist);  // 深拷贝
      } else if (value == 1) {
        this.list = [...this.olist].sort(this.sortAsc)
      } else if (value == 2) {
        this.list = [...this.olist].sort(this.sortDesc)
      }
    },
    changeTimeMenu(value) {

      if (value == 0) {
        this.list = [...this.olist]
      } else if (value == 1) {
        this.list = [...this.olist].sort(this.timesortAsc)
      } else if (value == 2) {
        this.list = [...this.olist].sort(this.timesortDesc)
      }
    },
    async getListData() {
      let res = null;
      if (this.type == 1) {
        res = await todogetmslikes({
          phone: this.userInfo.phone,

        })
      } else if (this.type == 2) {
        res = await todogetcollectlist({
          phone: this.userInfo.phone,

        })
      } else if (this.type == 3) {
        res = await todogetpinglist({
          phone: this.userInfo.phone,
        })
      }
      if (res.code == 200) {
        res.result.reverse().forEach((item) => {
          if (item.msobj) {
            this.list.push(item.msobj)
            this.olist.push(item.msobj)
          }
        })


        console.log(this.list)
      }
    }
  },
  mounted() {
    this.type = this.$route.params.type;
    if (this.type == 1) {
      this.title = '我的点赞(' + this.$route.query.value + ')'
    }
    else if (this.type == 2) {
      this.title = '我的收藏(' + this.$route.query.value + ')'
    }
    else if (this.type == 3) {
      this.title = '我的评论(' + this.$route.query.value + ')'
    }

    this.getListData()
  }
}
</script>
